﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data.SqlClient;
using System.Data;

namespace WebService_B2C
{
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    [WebService(Namespace = "http://localhost/WebService", Name = "Srv_getProducto", Description = "Servicio Web Retorna Info del Producto")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class Srv_getProducto : System.Web.Services.WebService
    {

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }

        [WebMethod]
        public Product getPrd_Codigo(long idProducto)
        {
            
            string DtsConnection = "Data Source=JHON-PC\\SQLEXPRESS;Initial Catalog=ProductosEcommerce;User ID=sa;Password=123456";

            SqlConnection Con = new SqlConnection(DtsConnection);
            Con.Open();

            SqlDataAdapter CMD = new SqlDataAdapter("Select * from Products where ProductId='" + idProducto + "'", Con);
            DataSet DS = new DataSet();

            CMD.Fill(DS, "DATOS");

            DataTable TablaProductos = DS.Tables[0];
            Product retorno = new Product();


            retorno.Name = TablaProductos.Rows[0]["Name"].ToString();
            retorno.Show = TablaProductos.Rows[0]["Show"].ToString();
            retorno.ShowDate = DateTime.Parse(TablaProductos.Rows[0]["ShowDate"].ToString());
            retorno.CityId = TablaProductos.Rows[0]["CityId"].ToString();
            retorno.ArrivalDate = DateTime.Parse(TablaProductos.Rows[0]["ArrivalDate"].ToString());
            retorno.DepartureDate = DateTime.Parse(TablaProductos.Rows[0]["DepartureDate"].ToString());
            retorno.TransportationRateId = long.Parse(TablaProductos.Rows[0]["TransportationRateId"].ToString());
            retorno.ShowRateId = long.Parse(TablaProductos.Rows[0]["ShowRateId"].ToString());
            retorno.AccommodationRateId = long.Parse(TablaProductos.Rows[0]["AccommodationRateId"].ToString());
            retorno.Image = TablaProductos.Rows[0]["Image"].ToString();

            return retorno;
        }

    }
}